from typing import List

"""
{
    "history": ["1+1等于多少", "1+1等于2", "你回答得很棒"]
    "query": "你回答的很棒"
}
"""


def to_message(history_message: List[str]):

    message_list = []
    for i, k in enumerate(history_message):
        if i % 2 == 0:
            user_message = {"role": "user", "content": k}
            message_list.append(user_message)
        else:
            assistant_message = {"role": "assistant", "content": k}
            message_list.append(assistant_message)

    return message_list


def max_len(message_list):
    total_tokens = 0
    for i in message_list:
        total_tokens = len(i["content"]) + total_tokens

    if total_tokens > 6800:
        message_list.pop(0)
        message_list.pop(0)
        return max_len(message_list)
    else:
        return message_list




